//父类
class People {
    constructor(name) {
        this.name = name
    }
    eat() {
        console.log(`${this.name} eats something`)
    }
}

// 子类
class Student extends People {
    constructor(name, number) {
        super(name);// 继承自父亲
        this.number = number //number是子类中的，所以自己处理
    }
    sayHi() {
        console.log(
            `姓名${this.name},学号${this.number}`
        )
    }
}

//子类
class Teacher extends People {
    constructor(name, major) {
        super(name);
        this.major = major
    }
    teach() {
        console.log(`${this.name}教授${this.major}`)
    }
}
//学生实例
const xialuo = new Student('夏洛', 100)

console.log(xialuo.name);
console.log(xialuo.number);
xialuo.sayHi();
xialuo.eat();

//老师实例

const wang = new Teacher('wls', '语文');
console.log(wang.name);
console.log(wang.major);
wang.teach();
wang.eat();

console.log(xialuo instanceof Student);// true
xialuo instanceof People // true
xialuo instanceof Object // true

console.log([] instanceof Array); // true
// [] instanceof Object // true
console.log({} instanceof Object); // true


// class 实际上是函数，可见是语法糖
typeof People //'function'
typeof Student // 'function'

// 隐式原型__proto__，显式原型 prototype
console.log(xialuo.__proto__);//People {constructor: ƒ, sayHi: ƒ}
console.log(Student.prototype);//People {constructor: ƒ, sayHi: ƒ}
console.log(xialuo.__proto__ === Student.prototype);// true


console.log(Student.prototype.__proto__); //{constructor: ƒ, eat: ƒ}
console.log(People.prototype); // {constructor: ƒ, eat: ƒ}
console.log(People.prototype === Student.prototype.__proto__);  // true

console.log(Student.__proto__ === People);
console.log(Student.protoype.__proto__ === People.prototype);